import Vue from 'vue'
import VueRouter from 'vue-router'

import layout from '../components/layout.vue'
// 导入home组件
import Home from '../views/index/index.vue'
//文章页
import Article from  '../views/article/index.vue'
//分类页
import categories from '../views/class/index.vue'
//分类页
import categorie from '../views/classitem/index.vue'
//标签页
import tags from '../views/tags/index.vue'
//标签页
import tag from '../views/tag/index.vue'
//归档
import archive from '../views/timeline/index.vue'
//相册
import photo from '../views/photo/index.vue'
//留言
import message from '../views/message/index.vue'

Vue.use(VueRouter)

const router = new VueRouter({
  mode: 'history',
  base: import.meta.env.BASE_URL,
  routes: [
    {
      path:'/',
      component:layout,
      children:[
        {
          path: '/',
          name: 'home',
          component: Home,
          beforeEnter(to,from,next){
            document.title='拾初心，记时光';
            next();
          }
        },
        {
          path: '/article/:id',
          name:'article',
          component: Article,
        },
        {
          path: '/categories',
          name:'class',
          component: categories,
          beforeEnter(to,from,next){
            document.title='分类';
            next();
          },
        },
        {
          path: '/categories/:id',
          component: categorie,
        },
        {
          path: '/tags',
          name:'tab',
          component: tags,
          beforeEnter(to,from,next){
            document.title='标签';
            next();
          }
        },
        {
          path: '/archive',
          name:'archive',
          component: archive,
          beforeEnter(to,from,next){
            document.title='归档';
            next();
          }
        },
        {
          path: '/photo',
          name:'photo',
          component: photo,
          beforeEnter(to,from,next){
            document.title='相册';
            next();
          }
        },
        {
          path: '/message',
          name:'message',
          component: message,
          beforeEnter(to,from,next){
            document.title='留言';
            next();
          }
        },
        {
          path: '/tag',
          component: tag,
        }
      ]
    }
  ],
  scrollBehavior(){
    return {
      top:0,
    }
  }
})

export default router
